package com.example.touchdemo.base;//package com.example.touchdemo.base;
//
//import android.os.Bundle;
//import android.text.TextUtils;
//import android.widget.Toast;
//
//import androidx.annotation.Nullable;
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.example.touchdemo.common.CustomToast;
//
//public abstract class BaseActivity extends AppCompatActivity {
//    private static final int FAST_CLICK_INTERVAL=500;
//    private long lastClickTime;
//    private  CustomToast mToast;
//
//    protected void oncreate(@Nullable Bundle savedInstanceState){
//        super.onCreate(savedInstanceState);
//        setContentView(getlayoutId());
//        init();
//    }
//
//    public abstract int getlayoutId();
//
//
//
//    public abstract void init();
//    public void showToast(int id) {
//        String ssdf = getString(id);
//        showToast(ssdf);
//    }
//    public void showToast(String text) {
//        if (!TextUtils.isEmpty(text)) {
//            if (mToast == null) {
//                mToast = new CustomToast(this);
//            }
//            mToast.setDuration(Toast.LENGTH_LONG);
//            mToast.setText(text);
//            mToast.show();
//        }
//    }
//
//    /**
//     * 判断是否是快速点击
//     * @return
//     */
//    public boolean isFastClick() {
//        long now = System.currentTimeMillis();
//        if (now - lastClickTime < FAST_CLICK_INTERVAL) {
//            return true;
//        }
//        lastClickTime = now;
//        return false;
//    }
//}


import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.touchdemo.common.CustomToast;


public abstract class BaseActivity extends AppCompatActivity {
    private static final int FAST_CLICK_INTERVAL = 500;//快速点击间隔
    private long lastClickTime;//last click time
    private CustomToast mToast;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//全局只能竖屏
        setContentView(getlayoutId());
        init();
    }

    public abstract int getlayoutId();

    public abstract void init();

    public void showToast(int id) {
        String ssdf = getString(id);
        showToast(ssdf);
    }

    public void showToast(String text) {
        if (!TextUtils.isEmpty(text)) {
            if (mToast == null) {
                mToast = new CustomToast(this);
            }
            mToast.setDuration(Toast.LENGTH_LONG);
            mToast.setText(text);
            mToast.show();
        }
    }

    /**
     * 判断是否是快速点击
     * @return
     */
    public boolean isFastClick() {
        long now = System.currentTimeMillis();
        if (now - lastClickTime < FAST_CLICK_INTERVAL) {
            return true;
        }
        lastClickTime = now;
        return false;
    }
}

